#include "main.h"
#include "CConsole.h"

CConsole::CConsole(void (*_func)(UINT GUIType, UINT Event, CGUIBase* Src, void* Dest)){
	GUI_PARAMS Params;
	ZeroMemory(&Params, sizeof(GUI_PARAMS));
	Params.pos=V(0, 0);
	Params.width=640;
	Params.height=480;
	Params.border=2;
	Params.enabled=true;
	Params.visible=true;
	Params.parent=NULL;

	GUI_COLORS colors;
	ZeroMemory(&colors,sizeof(GUI_COLORS));
	colors.BG=D3DCOLOR_ARGB(255, 100, 100, 100);
	colors.Border=CLR_BLACK;
	colors.Text=CLR_BLACK;
	colors.MouseDown=CLR_GREY;
	colors.MouseOver=CLR_WHITE;

	m_pWindow = new CGUIWindow(&Params, &colors, NULL, true, "Console");
	m_pWindow->SetEventFunction( _func );

	ZeroMemory(&Params, sizeof(GUI_PARAMS));
	Params.pos=V((float)m_pWindow->GetWidth()-24, 4);
	Params.width=20;
	Params.height=20;
	Params.hotkey=VK_SPACE;
	Params.border=0;
	Params.enabled=true;
	Params.visible=true;
	Params.parent=NULL;

	m_pWindow->Add(new CGUIButton(&Params, &colors, NULL, EVENT_CLOSEWINDOW, m_pWindow, "X"));

	ZeroMemory(&Params, sizeof(GUI_PARAMS));
	Params.pos=V(10, 30);
	Params.width=620;
	Params.height=412;
	Params.border=2;
	Params.enabled=true;
	Params.visible=true;
	Params.parent=m_pWindow;

	ZeroMemory(&colors,sizeof(GUI_COLORS));
	colors.BG=D3DCOLOR_ARGB(255, 64, 64, 64);
	colors.Border=CLR_BLACK;
	colors.Text=CLR_BLACK;
	colors.MouseDown=CLR_GREY;
	colors.MouseOver=CLR_BLACK;

	m_pOutputTextBox = new CGUITextBox(&Params, &colors, NULL, false, true, NULL, NULL, "YOOOOOOO SHITTY CONSOLE");
	m_pWindow->Add(m_pOutputTextBox);

	ZeroMemory(&Params, sizeof(GUI_PARAMS));
	Params.pos=V(10, 446);
	Params.width=620;
	Params.height=24;
	Params.hotkey=VK_RETURN;
	Params.border=2;
	Params.enabled=true;
	Params.visible=true;
	Params.parent=m_pWindow;

	m_pWindow->Add(new CGUITextBox(&Params, &colors, NULL, true, true, EVENT_CONSOLE, this, ""));
}

CConsole::~CConsole(){

}

void CConsole::addLine(std::string _line){
	m_pOutputTextBox->AddLine(_line);
}

void CConsole::Command(std::string _line){
	addLine(_line);
}

void CConsole::Command(CGUITextBox* Src){
	Command(Src->Getline(0));
	Src->SetText("");
}